/*
 * 
 * 
 * 
 */
package com.hboxs.asl.controller.admin;

import com.hboxs.asl.Message;
import com.hboxs.asl.Pageable;
import com.hboxs.asl.entity.YiYuanTrade;
import com.hboxs.asl.service.YiYuanTradeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.http.HttpSession;

import javax.annotation.Resource;

/**
 * Controller - 支付查看答案
 */
@Controller("adminYiYuanTradeController")
@RequestMapping("/asl-admin/yiyuan_trade")
public class YiYuanTradeController extends BaseController {

    @Resource(name = "yiYuanTradeServiceImpl")
    private YiYuanTradeService yiYuanTradeService;

    /**
     * 添加
     */
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String add(ModelMap model, HttpSession session) {
        return "/admin/yiyuan_trade/add";
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public String save(YiYuanTrade yiYuanTrade, RedirectAttributes redirectAttributes) {
        if (!isValid(yiYuanTrade)) {
            return ERROR_VIEW;
        }
        yiYuanTradeService.save(yiYuanTrade);
        addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
        return "redirect:list.htm";
    }

    /**
     * 编辑
     */
    @RequestMapping(value = "/edit", method = RequestMethod.GET)
    public String edit(Long id, ModelMap model, HttpSession session) {
        model.addAttribute("yiyuan_trade", yiYuanTradeService.find(id));
        return "/admin/yiyuan_trade/edit";
    }

    /**
     * 更新
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(YiYuanTrade yiYuanTrade, RedirectAttributes redirectAttributes) {
        if (!isValid(yiYuanTrade)) {
            return ERROR_VIEW;
        }
        yiYuanTradeService.update(yiYuanTrade, "");
        addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
        return "redirect:list.htm";
    }

    /**
     * 列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String list(Pageable pageable, ModelMap model) {
        model.addAttribute("page", yiYuanTradeService.findPage(pageable));
        return "/admin/yiyuan_trade/list";
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public
    @ResponseBody
    Message delete(Long[] ids) {
        yiYuanTradeService.delete(ids);
        return SUCCESS_MESSAGE;
    }

}
